/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/* nixonFTP
 * FTP client version 0.1
 * Copyright (C) 2010 NIXON Development Corporation.
 * All rights reserved.
 * http://members.shaw.ca/nixon.com
*/

package nixonftp;

import java.awt.Color;


public class NXFilter {
	public int type;
	//type parameters
	public static final int DATE = 0;
	public static final int SIZE = 1;
	public static final int NAME = 2;

	public int range;
	//range parameters
	public static final int BEFORE = 1;
	public static final int WITHIN = 0;
	public static final int LESS_THAN = 0;
	public static final int EQUAL_TO = 1;
	public static final int GREATER_THAN = 2;

	public int unit;
	//unit parameters
	public static final int SECONDS = 0;
	public static final int MINUTES = 1;
	public static final int HOURS = 2;
	public static final int DAYS = 3;
	public static final int WEEKS = 4;
	public static final int MONTHS = 5;
	public static final int YEARS = 6;

	public long value;

	public static final int BYTES = 0;
	public static final int KB = 1;
	public static final int MB = 2;
	public static final int GB = 3;

	public final int action;
	//action parameters;
	public static final int COLOR = 0;
	public static final int SHOW = 1;
	public static final int HIDE = 2;
	public Color color;

	//constructor for date/size
	public NXFilter(int type, int action, int range, long value, int unit) {
		this.type = type;
		this.action = action;
		this.range = range;
		this.value = value;
		this.unit = unit;
	}

	public void setColor(Color c) {
		this.color = c;
	}

	public String toString() {
		String s = "";
		String verb = getActionString();
		String strRange = getRangeString();
		String strUnit = getUnitString();
		
		if (type == SIZE) {
			s = verb + "files of size " + strRange + " " + this.value + " " + strUnit;
		} else if (type == DATE) {
			s = verb + "files modified " + strRange + " the past " + this.value + " " + strUnit;
		}
		if (action == COLOR) {
			//s += " with color (" + color.getRed() + "," + color.getGreen() + "," + color.getBlue() + ")";
			s += " with color";
		}
		return s;
	}

	private String getActionString() {
		switch (action) {
			case COLOR:
				return "Label ";
			case SHOW:
				return "Show only ";
			case HIDE:
				return "Hide ";
		}
		return null;
	}

	private String getRangeString() {
		if (type == SIZE) {
			switch (range) {
				case LESS_THAN:
					return "less than";
				case EQUAL_TO:
					return "equal to";
				case GREATER_THAN:
					return "greater than";
			}
		} else if (type == DATE) {
			switch (range) {
				case BEFORE:
					return "before";
				case WITHIN:
					return "within";
			}
		}
		return null;
	}

	private String getUnitString() {
		if (type == SIZE) {
			switch (unit) {
				case BYTES:
					return "bytes";
				case KB:
					return "KB";
				case MB:
					return "MB";
				case GB:
					return "GB";
			}
		} else if (type == DATE) {
			switch (unit) {
				case SECONDS:
					return "seconds";
				case MINUTES:
					return "minutes";
				case HOURS:
					return "hours";
				case DAYS:
					return "days";
				case WEEKS:
					return "weeks";
				case MONTHS:
					return "months";
				case YEARS:
					return "years";
			}
		}
		return null;
	}

	public Integer getUnitValue() {
		if (type == DATE) {
			switch (unit) {
				case SECONDS:
					return 1;
				case MINUTES:
					return 60;
				case HOURS:
					return 3600;
				case DAYS:
					return 86400;
				case WEEKS:
					return 604800;
				case MONTHS:
					return 2592000;
				case YEARS:
					return 31557600;
			}
		} else if (type == SIZE) {
			switch (unit) {
				case BYTES:
					return 1;
				case KB:
					return 1024;
				case MB:
					return 1048576;
				case GB:
					return 1073741824;
			}
		}
		return null;
	}
}
